<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@include file="/layout/head.jsp"%>

<link href="layout/manage.css" rel="stylesheet" type="text/css"
	media="screen" />
<script type="text/javascript" src="javascript/manage.js"></script>
</head>

<body>
	<%@include file="/layout/bodyHeader.jsp"%>

	<h1>Manage My Budget</h1>
	<c:if test="${fn:length(userMessages) > 0}">
		<div class="userMessages">

			<ul class="userMessages">
				<c:forEach items="${userMessages}" var="_userMessage">
					<li class="userMessage">${_userMessage}</li>
				</c:forEach>
			</ul>

		</div>
	</c:if>

	<form:form id="incomeForm" commandName="budget" method="post">

		<div class="post">
			<h2 class="title">
				<spring:message code="income.label" />
			</h2>
			<p class="meta">
				<spring:message code="wholeDollarNote" />
			</p>
			<div class="entry">

				<form:hidden path="budgetId" />

				<table class="noborder">
					<thead>
						<tr>
							<th><spring:message code="item.description.label" /></th>
							<th colspan="2"><spring:message code="item.amount.label" /></th>
						</tr>
					</thead>
					<c:forEach items="${budget.incomeItems}" var="_item"
						varStatus="_status">
						<tr id="incomeItemRow_${_status.index}">
							<td><form:hidden
									path="incomeItems[${_status.index}].incomeItemId" /> <form:input
									path="incomeItems[${_status.index}].description" size="20" /></td>
							<td><form:input path="incomeItems[${_status.index}].amount"
									size="8" /></td>
							<td><form:errors
									path="incomeItems[${_status.index}].description" /> <form:errors
									path="incomeItems[${_status.index}].amount" /></td>
						</tr>
						<tr>
						</tr>
					</c:forEach>
					<tr id="addIncomeItemButtonRow" class="addItemButtonRow">
						<td colspan="2"><input type="button" value="+"
							id="addIncomeItemButton" /></td>
						<td></td>
					</tr>
					<tr class="subtotalRow">
						<td class="subtotalLabel"><spring:message code="total.label" /></td>
						<td class="subtotal"><span id="incomeSubtotal">${incomeSubtotal}</span></td>
						<td></td>
					</tr>
				</table>

				<input type="submit"
					value="<spring:message code="saveButton.label" />" id="topSave" />
			</div>
		</div>
		<div class="post">
			<h2 class="title">
				<spring:message code="expenses.label" />
			</h2>
			<p class="meta">
				<spring:message code="wholeDollarNote" />
			</p>
			<div class="entry">

				<table class="noborder">
					<thead>
						<tr>
							<th><spring:message code="item.description.label" /></th>
							<th><spring:message code="item.category.label" /></th>
							<th colspan="2"><spring:message code="item.amount.label" /></th>
						</tr>
					</thead>
					<c:forEach items="${budget.expenseItems}" var="_item"
						varStatus="_status">
						<tr id="expenseItemRow_${_status.index}">
							<td id="expenseItemDescCell_${_status.index}"><form:hidden
									path="expenseItems[${_status.index}].expenseItemId" /> <form:input
									path="expenseItems[${_status.index}].description" size="20" /></td>
							<td><form:select
									path="expenseItems[${_status.index}].expenseCategory.categoryId"
									items="${expenseCategories}" itemLabel="displayName"
									itemValue="categoryId">

								</form:select></td>
							<td><form:input path="expenseItems[${_status.index}].amount"
									size="8" /></td>
							<td><form:errors
									path="expenseItems[${_status.index}].description" /> <form:errors
									path="expenseItems[${_status.index}].expenseCategory.categoryId" />
								<form:errors path="expenseItems[${_status.index}].amount" /></td>
						</tr>
						<tr>
						</tr>
					</c:forEach>
					<tr id="addExpenseItemButtonRow" class="addItemButtonRow">
						<td colspan="3"><input type="button" value="+"
							id="addExpenseItemButton" /></td>
						<td></td>
					</tr>
					<tr class="subtotalRow">
						<td class="subtotalLabel" colspan="2"><spring:message
								code="total.label" /></td>
						<td class="subtotal"><span id="expenseSubtotal">${expenseSubtotal}</span></td>
						<td></td>
					</tr>
				</table>

				<input type="submit"
					value="<spring:message code="saveButton.label" />" id="bottomSave" />

			</div>
		</div>

	</form:form>

	<div style="clear: both;">&nbsp;</div>


	<%@include file="/layout/bodyFooter.jsp"%>
</body>
</html>
